## -*- coding: utf-8 -*-

import web
from sqlalchemy import create_engine
from web.contrib.template import render_mako   #导入mako模板支持
import sys,os
import db
#Options related to sessions
web.config.session_parameters['cookie_name'] = 'webpy_session_id'
web.config.session_parameters['cookie_domain'] = None
web.config.session_parameters['timeout'] = 86400, #24 * 60 * 60, # 24 hours   in seconds
web.config.session_parameters['ignore_expiry'] = False #如果为True，session就永不过期 
web.config.session_parameters['ignore_change_ip'] = False #如果为true，就表明只有在访问该session的IP与创建该session的IP完全一致时，session才被允许访问
web.config.session_parameters['secret_key'] = 'fLjUfxqXtfNoIldA0A0J' #为session加密提供一个字符串种子 
web.config.session_parameters['expired_message'] = '登陆超时，请重新登陆' #session过期时显示的提示信息。 


###########################

SALT = 'magicxp'
#数据库连接
web.webapi.internalerror = web.debugerror
#middleware = web.reloader

# set template caching to false for debugging purposes
cache = False

# secret stuff for user auth see app.utilities.auth
# TODO should probably change to a better value
encryptionkey = 'something stored in some config file'

# mail settings for emailing passwords and whatnot
mailhost = 'localhost'
mailsender = 'admin@yerp'

# set our global base template
#base = web.template.render('app/views/base/', cache=cache)
#使用自带的模板
#view = web.template.render('templates')
#使用mako模板

class render_mako:
    """Rendering interface to Mako Templates.

    Example:

        render = render_mako(directories=['templates'])
        render.hello(name="mako")
    """
    def __init__(self, *a, **kwargs):
        from mako.lookup import TemplateLookup 
        self._lookup = TemplateLookup(*a, **kwargs)
    def __getattr__(self, name):
        # Assuming all templates are html
        path = name + ".html"
        t = self._lookup.get_template(path)
        return t.render

view=render_mako()
upload_dir = os.path.dirname(__file__).replace('\\','/')+'/static/upload'
#render = web.template.render('templates/', base = 'layout', globals = {'session':session})
#db = web.database(dbn='oracle',user='zweberp', pw='1', db='ora')
db_path = os.path.dirname(db.__file__).replace('\\','/')
engine = create_engine('sqlite:///'+db_path+'/database.db', echo=True)
# oracle - cx_oracle is the default driver
#engine = create_engine('oracle://yferp:1@127.0.0.1:1521/ora',echo=True,pool_size=20, max_overflow=0)
#DB='oracle'
# oracle via TNS name
#engine = create_engine('postgresql+psycopg2://yerp:1@127.0.0.1/yerp2',echo=True,encoding='utf-8',pool_size=20, max_overflow=0)
